<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <cpn></cpn>

    <cpn>
      <!-- 目的是获取子组件中的pLanguages,这里拿不到,所以就需要传过去 -->
      <!-- 为了拿到传过来的data 必须要有template -->
      <template slot-scope="slot">
        <!-- <span v-for="item in slot.data">{{item}} - </span> -->
        <!-- join 数组转字符串,并且以后面的参数分割 -->
        <span>{{slot.data.join(' - ')}}</span>
      </template>
    </cpn>


    <cpn>
      <template slot-scope="slot">
        <span v-for="item in slot.data">{{item}} * </span>
      </template>
    </cpn>
  </div>

  <template id="cpn">
    <div>
      <!-- data是随便取的 -->
      <slot :data="pLanguages">
        <ul>
          <li v-for="item in pLanguages">{{item}}</li>
        </ul>
      </slot>
    </div>
  </template>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {},
      methods: {},
      components: {
        cpn: {
          template: '#cpn',
          data() {
            return {
              pLanguages: ['JavaScript', 'C++', 'Java', 'C#', 'Python', 'Go', 'Swift']
            }
          }
        }
      }
    });
  </script>
</body>

</html>